package com.class5.springboot.frame.context.bean;

import javax.servlet.http.HttpServletRequest;

import com.class5.springboot.filter.JwtFilter;
import com.class5.springboot.frame.web.result.ResultFailure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


import lombok.extern.slf4j.Slf4j;
/**
 * rest异常处理
 * @author Administrator
 *
 */
@ControllerAdvice
@Slf4j
public class ExceptionHandlerBean {

	@Autowired
	@Lazy
	private JwtFilter jwtFilter;

	//是否在调试模式，调试模式下将直接输出验证码
  	@Value("${myconfig.security.debugModel}")
  	private String debugModel;
	@ExceptionHandler(value = Throwable.class)
	@ResponseBody
	public Object baseErrorHandler(HttpServletRequest req, Exception e)
			throws Exception {
		String uri = req.getRequestURI();
		if(uri.indexOf("/localInvoke") >= 0){
			throw e;
		}
		log.error("Request Error:", e);
		return new ResultFailure(e, "true".equals(debugModel), req);
	}
}
